<template>
  <div class="wrapper">
    <div style="margin: 150px auto; width: 350px;height: 300px;padding: 20px;border-radius: 10px">
      <div style="margin: 20px 0;text-align: center;font-size: 30px;color: white"><b>登 录</b></div>
      <el-input placeholder="请输入登录账号" size="medium" style="margin: 10px 0" prefix-icon="el-icon-user" v-model="user.account"></el-input>
      <el-input placeholder="请输入登录密码" size="medium" style="margin: 10px 0" prefix-icon="el-icon-lock" show-password v-model="user.password"></el-input>
      <div style="margin: 10px; text-align: center">
        <el-button type="primary" size="small" autocomplete="off" @click="login">登陆</el-button>
        <el-button type="warning" size="small" autocomplete="off" @click="$router.push('/signup')">注册</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        id:'',
        account: '',
        password:'',
        userType:'',
        type:''
      }
    }
  },
  methods: {
    login() {
      console.log(this.user)
      let _this = this
      axios.post('http://127.0.0.1:3049/LoginDetails/check', this.user).then(function (response) {
        console.log(response.data)
        _this.user.id = response.data.data.id;
        if (response.data.code == 200) {
          _this.$message({
            message: '登录成功',
            type: 'success'
          });
          _this.user.id = response.data.data.id
          if (response.data.data.type == 1) {
            _this.user.userType=1
            _this.user.type = '买家'
          }
          else if (response.data.data.type == 2) {
            _this.user.userType=2
            _this.user.type = '卖家'
          }
          else if (response.data.data.type == 3) {
            _this.user.userType=3
            _this.user.type = '管理员'
          }
          console.log(_this.user)
          localStorage.setItem("user",JSON.stringify(_this.user))//存储信息到本地浏览器
          _this.$router.push('/Manager')
        } else {
          _this.$message({
            message: '登录失败',
            type: 'error'
          });
        }
      })
    }
  }
}

</script>

<style>
.wrapper{
  background:url("./pic/background.jpg");
  width:100%;
  height:100%;
  position:fixed;
  background-size:100% 100%;
}

</style>